const mysql = require("mysql");

const pool = mysql.createPool({
    host: "127.0.0.1",
    port: 3306,
    user: "root",
    password: "root",
    database: "mydb",
    connectTimeout: 3000,
    connectionLimit: 10
})

const query = (sql, arr) => {
    return new Promise((resolve, reject) => {
        pool.getConnection(function(err, connection) {
            if (err) reject(err);
            connection.query(sql, arr, function(err, resluts) {
                if (err) reject(err);
                resolve(resluts);
                connection.release();
            })
        })
    })
}

exports.query = query;